@import './theme/default';
@import './theme/font';

$popupWidth: 240px;
$menuHeight: 180px;

@mixin tag-style {
  @include theme-color(border-color, stroke, 5);
  border-radius: 2px;
  margin: 4px 4px 4px 0;
  padding: 0 4px;
  line-height: 16px;
  font-size: $font-size-small;
  display: flex;
  align-items: center;
  word-break: break-all;
  box-sizing: border-box;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.zent-cascader-v2 {
  display: flex;
  flex-wrap: wrap;
  cursor: pointer;
  font-size: $font-size-normal;
  position: relative;
  text-align: left;
  user-select: none;
  width: $popupWidth;
  vertical-align: middle;
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  border-radius: 2px;
  line-height: 18px;
  padding: 6px 30px 6px 12px;
  min-height: 32px;
  transition: border-color 0.25s;
  @include theme-color(border-color, stroke, 5);
  @include theme-color(background-color, stroke, 9);

  &-tag__list {
    display: flex;
    flex-wrap: wrap;
    cursor: pointer;
    overflow: hidden;
  }

  &-tag-collapsed {
    &-trigger {
      @include theme-color(background-color, stroke, 7);
      @include tag-style;
      cursor: pointer;
      justify-content: center;
      flex-shrink: 0;
      margin-top: 2px;
      margin-bottom: 2px;
    }

    &-content {
      @include font-normal;
      max-width: 216px;
      max-height: 80px;
      overflow-y: auto;
      word-break: break-all;
      @include theme-color(border-color, stroke, 5);
    }
  }

  .zenticon-down,
  .zenticon-close-circle {
    position: absolute;
    right: 8px;
    top: 5px;
    font-size: 20px;
  }

  .zenticon-down {
    transition: transform 0.25s;
    @include theme-color(color, stroke, 2);
  }

  .zenticon-close-circle {
    @include theme-color(color, stroke, 2, 0.6);
  }

  &--active {
    @include theme-color(border-color, primary, 3);
  }

  &--disabled {
    cursor: not-allowed;
    @include theme-color(color, stroke, 4);
    @include theme-color(border-color, stroke, 5);
    @include theme-color(background-color, stroke, 8);

    &:hover {
      @include theme-color(color, stroke, 4);
      @include theme-color(border-color, stroke, 5);
      @include theme-color(background-color, stroke, 8);
      box-shadow: none;
    }

    .zenticon-down {
      @include theme-color(color, stroke, 4);
    }
  }

  &--placeholder {
    @include theme-color(color, stroke, 4);
  }

  &--text {
    display: inline-block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  &--multiple {
    padding-top: 4px;
    padding-bottom: 4px;
    .zent-cascader-v2--tag + .zent-cascader-v2--search {
      margin-top: 2px;
    }
    .zent-cascader-v2--placeholder {
      line-height: 22px;
    }
    &-collapsed {
      display: flex;
      flex-wrap: nowrap;
    }
  }

  &--search-empty,
  &__menu-empty {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    @include theme-color(color, stroke, 4);
  }

  &--search-empty {
    width: 100%;
  }

  &__menu-empty {
    width: $popupWidth;
  }

  &--search {
    outline: none;
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
    width: 100%;

    &::placeholder {
      @include theme-color(color, stroke, 4);
    }

    &-item {
      @include theme-color(color, stroke, 1);
      font-size: $font-size-normal;
      cursor: pointer;
      white-space: nowrap;
      position: relative;
      height: 32px;
      line-height: 32px;
      text-align: left;
      padding: 0 10px;
      box-sizing: border-box;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;

      &:hover {
        @include theme-color(background-color, primary, 8);
      }

      &--disabled {
        @include theme-color(color, stroke, 4);
        cursor: not-allowed;

        &:hover {
          @include theme-color(background-color, stroke, 9);
        }
      }

      &--multiple {
        cursor: initial;
      }

      .zent-cascader-v2--highlight {
        font-style: normal;
        background-color: initial;
        @include theme-color(color, primary, 4);
      }
    }
  }

  &__menu {
    @include theme-color(border-right, stroke, 6);
    display: inline-block;
    vertical-align: top;
    min-width: 111px;
    height: $menuHeight;
    list-style: none;
    margin: 0;
    padding: 0;
    border-right-width: 1px;
    border-right-style: solid;
    overflow: auto;

    &:last-child {
      border-right: 0;
    }

    &-item {
      @include theme-color(color, stroke, 1);
      font-size: $font-size-normal;
      cursor: pointer;
      white-space: nowrap;
      transition: all 0.3s;
      position: relative;
      height: 32px;
      line-height: 32px;
      text-align: left;
      padding: 0 30px 0 12px;
      box-sizing: border-box;
      width: 240px;
      max-width: 360px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: flex;

      &--leaf {
        padding-right: 10px;
      }

      &-label {
        display: inline-block;
        vertical-align: middle;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      &-icon {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 18px;
        @include theme-color(color, stroke, 3);
      }

      &-loading {
        @include theme-border(1px, solid, primary, 4);
        width: 12px;
        height: 12px;
        margin-top: -6px;
        position: absolute;
        display: inline-block;
        animation: zent-ani-spin 1s infinite linear;
        border-radius: 50%;
        right: 10px;
        top: 50%;
        border-top-color: transparent;
        box-sizing: border-box;
      }

      &:hover {
        @include theme-color(background-color, stroke, 8);
      }

      &--active:not(&--multiple) {
        @include theme-color(background-color, primary, 8);
      }

      &--active:not(&--multiple--checkbox) {
        font-weight: $font-weight-medium;
      }

      &--disabled {
        @include theme-color(color, stroke, 4);
        cursor: not-allowed;

        &:hover {
          @include theme-color(background-color, stroke, 9);
        }
      }

      &--multiple {
        &--normal {
          cursor: pointer;
        }
        &--checkbox {
          cursor: initial;
        }
      }
    }

    .zent-checkbox-wrap {
      margin-right: 8px;
    }

    &-scroller {
      height: $menuHeight;
      &-loading.zent-loading {
        text-align: center;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 7px 0;
      }
    }
  }

  &--tag {
    @include theme-color(border-color, stroke, 5);
    border-width: 1px;
    border-style: solid;
    border-radius: 2px;
    margin: 2px 4px 2px 0;
    padding-left: 4px;
    line-height: 16px;
    font-size: $font-size-small;
    display: flex;
    align-items: center;
    cursor: default;
    overflow: hidden;

    &-path {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    &-close {
      @include theme-color(color, stroke, 3);
      cursor: pointer;
      font-size: 16px;
    }
  }

  &__list {
    font-size: 0;
    padding: 12px 0 12px 12px;
    min-height: 215px;
    box-sizing: border-box;

    &-item {
      display: inline-block;
      box-sizing: border-box;
      margin: 4px 4px;
    }

    &-link {
      cursor: pointer;
      display: inline-block;
      font-size: $font-size-normal;
      padding: 0 8px;
      line-height: 24px;
      vertical-align: middle;
      width: 114px;
      box-sizing: border-box;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &:hover:not(.zent-cascader-v2__list-link--active) {
        @include theme-color(background-color, stroke, 8);
      }

      &--active {
        @include theme-color(background-color, primary, 8);
        @include theme-color(color, stroke, 1);
        font-weight: $font-weight-medium;
        border-radius: 2px;
      }
    }
  }

  &__tabs {
    .zent-tabs {
      &-nav {
        margin-bottom: 0;
      }

      &-nav-content {
        height: auto;
      }

      &-panel-wrapper {
        margin-top: 0;
      }

      &-tab {
        border-radius: 0;
      }

      &-tab-inner {
        max-width: 96px;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }

  &__popup {
    z-index: 2000;

    &-inner {
      @include theme-color(background-color, stroke, 9);
      @include theme-shadow(layer);
      width: 512px;
      box-sizing: border-box;

      &-menu,
      &-search {
        width: auto;
        white-space: nowrap;
      }

      &-search {
        max-height: $menuHeight;
        overflow-y: auto;
        width: $popupWidth;
      }
    }
  }

  &__loading {
    position: relative;
    vertical-align: middle;

    &-label {
      line-height: 16px;
      display: inline-block;
      vertical-align: middle;
      max-width: 78px;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    &-icon {
      @include theme-color(border-color, primary, 3);
      display: inline-block;
      position: relative;
      vertical-align: middle;
      height: 12px;
      width: 12px;
      border-radius: 50%;
      border-width: 1px;
      border-style: solid;
      margin-left: 5px;

      &:after {
        @include theme-color(background, stroke, 9);
        content: '';
        display: inline-block;
        position: absolute;
        height: 10px;
        width: 4px;
        animation: 1s linear zent-ani-spin infinite;
        transform-origin: 8px 3px;
        left: -1px;
        top: 4px;
      }
    }
  }
}
